"""
    Contains daily and monthly registers.
"""

from sqlobject import DatabaseIndex
from sqlobject.col import ForeignKey, CurrencyCol, DateCol, BoolCol
from mnemoply.model.model_object import ModelObject
from mnemoply.model.hub import __connection__
from mnemoply.utils import format_currency
from datetime import date

class DailyPaymentRegister(ModelObject):
    """
        Admins in each register create this reports every days.
        We summarize all payment from one register and create this
        document with this sum.
    """

    model_title = _("Daily Payment Register")

    creation_date = DateCol(notNull=True, default=lambda: date.today(), title=_("Creation date"))
    organization = ForeignKey('Organization', notNull=True, title=_("Organization"))
    cashRegister = ForeignKey('CashRegister', notNull=True, title=_("Cash register"))
    amount = CurrencyCol(notNull=True, title=_("Amount"))

    daily_payment_register_unique = DatabaseIndex('creation_date', 'organization', 'cashRegister', unique=True)

    title = property(lambda self: "%s %s-%s: %s" % ( \
        self.creation_date, self.organization.title, self.cashRegister.title,
        format_currency(self.amount)
    ))